package org.windblog.core.servlet.link;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.windblog.core.LinkService;
import org.windblog.core.entity.Link;




@SuppressWarnings("serial")
public class AddLinkServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse response)
			throws ServletException, IOException {
		
		
		String name = req.getParameter("name").trim();
		String url = req.getParameter("url");
		String description = req.getParameter("description");
		String target = req.getParameter("target");
		if(target==null)
		{
			target="";
		}
		Boolean visible = null;
		String[] chk = req.getParameterValues("visible");
		if(chk==null)
		{
			visible = true;
		}else{
			visible = false;
		}
		
		if(name!=null)
		{
			Link link = new Link();
			link.setName(name);
			link.setUrl(url);
			link.setDescription(description);
			link.setTarget(target);
			link.setDate(new Date());
			link.setVisible(visible);

			LinkService.setLink(link);
			response.sendRedirect("/admin/linkManager.jsp?message=1");
		}else{
			response.sendRedirect("/admin/linkManager.jsp?message=2");
		}
	}
	
}
